package com.hadoop.mapReduce.wordCountMine.hdfsDemo;

import com.hadoop.mapReduce.wordCountMine._01MyContext;
import com.hadoop.mapReduce.wordCountMine._02MyMapper;

/**
 * 自定义word count Mapper实现类
 * Mapper:
 *      遍历数据
 *      处理数据
 */
public class WordCountMapper implements _02MyMapper {

    public void map(String line, _01MyContext context) {
        //line = "hadoop	welcome"
        String[] words = line.split(" ");
        //words = [hadoop,welcome]

        for(String word : words) {
            //word1 = hadoop  word2 = welcome
            Object value = context.get(word);
            if(value == null) { // 表示没有出现过该单词
                context.write(word, 1);
            } else {
                int v = Integer.parseInt(value.toString());
                context.write(word, v+1);  // 取出单词对应的次数+1
            }
        }

    }


    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(i%4);
        }

    }
}
